#include<bits/stdc++.h>

using namespace std;

int main()
{
	long long t,ans;
	int a[200010];
	double avr,sum;
	cin>>t;
	while(t--)
	{
		map<long long, long long> mp;
		int n;
		ans = 0;
		sum = 0;
		cin>>n;
		for(int i = 1; i <= n; i++)
		{
			cin>>a[i];
			if(mp[a[i]] == 0) mp[a[i]] = 1;
			else mp[a[i]] += 1;
			sum += a[i];
		}
		avr = sum / n;
		double temp = sum - (avr * (n - 2));
		if(temp != (int)temp)
		{
			cout<<"0"<<endl;
		}
		else
		{
			for(int i = 1; i <= n; i++)
			{
				if(mp[a[i]] == 0) continue;
				else if(a[i]*2 == temp)
				{
					ans += mp[a[i]] * (mp[a[i]]-1) / 2;
					mp[a[i]] = 0;
				}
				else if(mp[temp-a[i]] != 0)
				{
					ans += mp[a[i]] * mp[temp-a[i]];
					mp[a[i]] = 0;
					mp[temp-a[i]] = 0;
				}
			}
			cout<<ans<<endl;
		}
	}
	return 0;
}



